package io;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class BioServer {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("等待连接");
        while (true) {
            Socket socket = serverSocket.accept();
            System.out.println("获得连接" + socket.hashCode());

            new Thread(()->{
                byte[] bf = new byte[1024];
                try (InputStream inputStream = socket.getInputStream();){
                    System.out.println(Thread.currentThread().getName()+"读到数据：");
                    int read = inputStream.read(bf);
                    System.out.println(Thread.currentThread().getName() + new String(bf) + read);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
